package com.dadaguai.mapper;

import com.dadaguai.domain.LikeRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author 王半仙
 * @description 针对表【like_record(点赞记录)】的数据库操作Mapper
 * @createDate 2023-10-20 11:28:40
 * @Entity com.dadaguai.domain.LikeRecord
 */
public interface LikeRecordMapper extends BaseMapper<LikeRecord> {

    /**
     * 查询用户是否点赞
     *
     * @param articleId 主体id
     * @param userId    用户id
     * @return count
     */
    @Select("select count(*) from like_record where object_id = #{articleId} and user_id = #{userId} and op_type = 0")
    Integer selectGoodCount(@Param("articleId") String articleId, @Param("userId") String userId);

    /**
     * 删除点赞记录
     *
     * @param articleId
     * @param userId
     */
    @Delete("delete from like_record where user_id = #{userId} and object_id = #{articleId} and op_type = 0")
    void deleteGoodCount(@Param("articleId") String articleId, @Param("userId") String userId);

}




